package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.project.RCSaleCommissionPayment;
import com.shrct.businessprocess.project.RCSaleCommissionPayment4InputSettlementYear;
import com.shrct.businessprocess.project.RCSaleCommissionYearPayment;
import com.shrct.businessprocess.project.RCSalesAssignment;
import com.shrct.businessprocess.project.impl.RCSaleCommissionPayment4SettlementYearImpl;
import com.shrct.businessprocess.project.proxy.RCSaleCommissionPayment4InputSettlementYearProxy;
import edu.fudan.mylang.common.NumberExtensions;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Collection;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCSALECOMMISSIONPAYMENT4INPUTSETTLEMENTYEAR_TYPE")
public class RCSaleCommissionPayment4InputSettlementYearImpl extends RCSaleCommissionPayment4SettlementYearImpl implements RCSaleCommissionPayment4InputSettlementYear {
  public RCSaleCommissionPayment4InputSettlementYearImpl() {
    super();
  }
  
  public RCSaleCommissionPayment4InputSettlementYearImpl(final RCSaleCommissionPayment payment) {
    super( payment);
    
  }
  
  private Integer settlementYear;
  
  public Integer getSettlementYear() {
    return this.settlementYear;
  }
  
  public RCSaleCommissionPayment4InputSettlementYear setSettlementYear(final Integer settlementYear) {
    this.settlementYear = settlementYear;
    return this;			
    
  }
  
  public Double getTotalAmountTarget() {
    return Double.valueOf(0d);
  }
  
  public Double getTotalPaidAmount() {
    return Double.valueOf(0d);
  }
  
  public Double getTotalSettlementAmount() {
    return Double.valueOf(0d);
  }
  
  public Double getTax4ThisYear() {
    Double _xblockexpression = null;
    {
      RCSaleCommissionPayment _payment = this.getPayment();
      RCSaleCommissionYearPayment _yearPayment = _payment.getYearPayment();
      final Integer paymentYear = _yearPayment.getYear();
      final Integer settlementYear = this.getSettlementYear();
      RCSaleCommissionPayment _payment_1 = this.getPayment();
      RCSaleCommissionYearPayment _yearPayment_1 = _payment_1.getYearPayment();
      final RCSalesAssignment saler = _yearPayment_1.getSaler();
      IGenericQuery<RCSaleCommissionPayment4InputSettlementYear> query=getObjectFactory().createGenericQuery(RCSaleCommissionPayment4InputSettlementYear.class,"select e from com.shrct.businessprocess.project.impl.RCSaleCommissionPayment4InputSettlementYearImpl as e   where ((((e.payment.yearPayment.saler) = (:saler)) and ((e.settlementYear) = (:settlementYear))) and ((e.payment.yearPayment.year) = (:paymentYear))) and  e.active = 1      ").setParameter("saler",saler).setParameter("settlementYear",settlementYear).setParameter("paymentYear",paymentYear);
      Collection<RCSaleCommissionPayment4InputSettlementYear> _list = query.list();
      final Function1<RCSaleCommissionPayment4InputSettlementYear,Double> _function = new Function1<RCSaleCommissionPayment4InputSettlementYear,Double>() {
          public Double apply(final RCSaleCommissionPayment4InputSettlementYear it) {
            Double _tax = it.getTax();
            return _tax;
          }
        };
      Iterable<Double> _map = IterableExtensions.<RCSaleCommissionPayment4InputSettlementYear, Double>map(_list, _function);
      final Function2<Double,Double,Double> _function_1 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce = IterableExtensions.<Double>reduce(_map, _function_1);
      Double _nullsafe = NumberExtensions.nullsafe(_reduce);
      _xblockexpression = (_nullsafe);
    }
    return _xblockexpression;
  }
  
  public Double getTotalTax() {
    Double _xblockexpression = null;
    {
      final Integer settlementYear = this.getSettlementYear();
      RCSaleCommissionPayment _payment = this.getPayment();
      RCSaleCommissionYearPayment _yearPayment = _payment.getYearPayment();
      final RCSalesAssignment saler = _yearPayment.getSaler();
      IGenericQuery<RCSaleCommissionPayment4InputSettlementYear> query=getObjectFactory().createGenericQuery(RCSaleCommissionPayment4InputSettlementYear.class,"select e from com.shrct.businessprocess.project.impl.RCSaleCommissionPayment4InputSettlementYearImpl as e   where (((e.payment.yearPayment.saler) = (:saler)) and ((e.settlementYear) = (:settlementYear))) and  e.active = 1      ").setParameter("saler",saler).setParameter("settlementYear",settlementYear);
      Collection<RCSaleCommissionPayment4InputSettlementYear> _list = query.list();
      final Function1<RCSaleCommissionPayment4InputSettlementYear,Double> _function = new Function1<RCSaleCommissionPayment4InputSettlementYear,Double>() {
          public Double apply(final RCSaleCommissionPayment4InputSettlementYear it) {
            Double _tax = it.getTax();
            return _tax;
          }
        };
      Iterable<Double> _map = IterableExtensions.<RCSaleCommissionPayment4InputSettlementYear, Double>map(_list, _function);
      final Function2<Double,Double,Double> _function_1 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce = IterableExtensions.<Double>reduce(_map, _function_1);
      Double _nullsafe = NumberExtensions.nullsafe(_reduce);
      _xblockexpression = (_nullsafe);
    }
    return _xblockexpression;
  }
  
  public static RCSaleCommissionPayment4InputSettlementYear create(final RCSaleCommissionPayment payment, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.project.RCSaleCommissionPayment4InputSettlementYear rCSaleCommissionPayment4InputSettlementYear = new com.shrct.businessprocess.project.impl.RCSaleCommissionPayment4InputSettlementYearImpl(
    	payment
    );
    objectFactory.create(rCSaleCommissionPayment4InputSettlementYear);
    return rCSaleCommissionPayment4InputSettlementYear;			
    
  }
  
  public static RCSaleCommissionPayment4InputSettlementYear createRCSaleCommissionPayment4InputSettlementYearImpl(final RCSaleCommissionPayment payment, final IObjectFactory objectFactory, final Procedure1<RCSaleCommissionPayment4InputSettlementYear> init) {
    com.shrct.businessprocess.project.RCSaleCommissionPayment4InputSettlementYear rCSaleCommissionPayment4InputSettlementYear = new com.shrct.businessprocess.project.impl.RCSaleCommissionPayment4InputSettlementYearImpl(
    	payment
    );
    objectFactory.create(rCSaleCommissionPayment4InputSettlementYear);
    init.apply(rCSaleCommissionPayment4InputSettlementYear);
    
    return rCSaleCommissionPayment4InputSettlementYear;			
    
  }
  
  public RCSaleCommissionPayment4InputSettlementYearProxy toProxy() {
    com.shrct.businessprocess.project.proxy.RCSaleCommissionPayment4InputSettlementYearProxy proxy = new com.shrct.businessprocess.project.proxy.RCSaleCommissionPayment4InputSettlementYearProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
